<?php

namespace iBrand\Shop\Server\Controllers\V2;

use iBrand\Common\Controllers\Controller;
use iBrand\Shop\Core\Repositories\ClerkRepository;

class ClerkController extends Controller
{
	protected $clerkRepository;

	public function __construct(ClerkRepository $clerkRepository)
	{
		$this->clerkRepository = $clerkRepository;
	}

	public function list()
	{
		$clerk = auth('clerk')->user();

		$list = $this->clerkRepository->getClerkList(['status' => 1, 'shop_id' => $clerk->shop_id, 'id' => ['!=', $clerk->id]]);
		if ($list && $list->count() > 0) {
			$data = $list->toArray();

			array_unshift($data, $clerk->toArray());
		} else {
			$data = [$clerk->toArray()];
		}

		return $this->success($data);
	}
}